﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 简单工厂02
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("想开什么车（Benz、BMW）");
            string str = Console.ReadLine();
            Car c = Driver.SelectCar(str);
            c.Run();
        }
    }

    interface Car
    {
        void Run();
    }

    class Benz :Car
    {
        public void Run()
        {
            Console.WriteLine("奔驰跑");
        }
    }
    class BMW : Car
    {
        public void Run()
        {
            Console.WriteLine("BMW跑");
        }
    }

    /// <summary>
    /// 工厂类
    /// </summary>
    class Driver
    {
        public static Car SelectCar(string strCarType)
        {
            Car car = null;
            if (strCarType == "Benz")
            {
                car = new Benz();
            }
            else if (strCarType == "BWM")
            {
                car = new BMW();
            }
            return car;
        }
    }
}
